<?php

namespace app\api\logic;
use app\api\model\Teacher;
use think\Db;

/**
 * Created by PhpStorm.
 * User: HVAI
 * Date: 2018/6/6
 * Time: 22:33
 */
class TeacherLogic{

    public function text(){
//        return Teacher::get(2)->hasOneG;

//        $t_g = Teacher::get(9)->hasOneG();
//
//        $res = $t_g->save(['class_name'=>'go']);
//
//        if($res){
//            return 200;
//        }else{
//            return 3002;
//        }


        Db::listen(function ($sql, $time, $explain) {
            // 记录SQL
            echo $sql . ' [' . $time . 's]'."<br/>";
        });


//        $teacher = new Teacher();
//
//        $grade= [
//            //当前模型所关联的关系名称=>'需要保持的数据'
//            'hasOneG'=>['class_name'=>'swoole']
//        ];
//
//        $teacherData = [
//            'name'=>'hvai',
//            'sex'=>'男',
//            'age'=>20,
//        ];
//        $res =  $teacher->together($grade)->save($teacherData);
//
//        if($res){
//            return 200;
//        }else{
//            return 3002;
//        }
        //关联跟新
//        $teacher =  Teacher::get(3);
//
//        $teacher->sex = '男';
//        $teacher->hasOneG->class_name = 'js';
//
//        $res  =  $teacher->together('hasOneG')->save();



        if($res){
            return 200;
        }else{
            return 3002;
        }

    }
}